import { createRouter, createWebHashHistory } from 'vue-router'
import { ElMessage } from 'element-plus'
import Home from '../views/Home.vue'
import NProgress from "nprogress"; // 导入 nprogress模块
import "nprogress/nprogress.css"; // 导入样式，否则看不到效果
NProgress.configure({ showSpinner: false }); // 显示右上角螺旋加载提示
const routes = [
  {
    path: '/',
    name: 'home',
    component: Home,
    // redirect:"/Home",
    meta:{
      title:'首页'
    },
  },
  {
    name:'product',
    path: '/Product',
    meta: {
        title: '产品与服务'
    },
    component:()=>import('@/views/Product/index.vue')
  },
  {
    name:'cooperate',
    path: '/Cooperate',
    meta: {
        title: '合作伙伴招募'
    },
    component:()=>import('@/views/Cooperate/index.vue')
  },
  {
    name:'aboutUs',
    path: '/AboutUs',
    meta: {
        title: '关于我们'
    },
    component:()=>import('@/views/AboutUs/index.vue')
  },
  {
    name:'helpCenter',
    path: '/HelpCenter',
    meta: {
        title: '帮助中心'
    },
    component:()=>import('@/views/HelpCenter/index.vue')
  },
  {
    name: '404',
    path: '/404',
    meta: {
        title: '页面不存在'
    },
    component: () => import('@/views/404.vue')
  },
]


const router = createRouter({
  history: createWebHashHistory(),
  routes
})

// 路由守卫
router.beforeEach(async (to, from, next) => {
  // console.log(to,"to");  
  NProgress.start(); //开启进度条
  if(to.name){
    next()
    
  }else{
    next("/404")
  }
})
router.afterEach((to,from) => {
  NProgress.done(); //完成进度条
  if(from.path == "/login"){
    ElMessage({
      message: '登录成功',
      type: 'success',
      duration:1000
    })
  }
  });
export default router
